<template>
	<view @click.stop="goToZfbAuthent" v-if="judgeGopayOrQianyue()"
		:class="{actionBtn: true, actionBtn0: position == 0, actionBtn1: position == 1, actionBtn2: position == 2, actionBtn3: position == 3 }">
		人脸识别
	</view>
</template>

<script>
	import {
		checkPosition,
		getOrderId
	} from "../utils/checkShowBtn.js"

	export default {
		name: "maiduan",

		props: {
			order: {
				type: Object,
				default: {},
			}, // 订单对象
			isUsedInList: {
				type: Boolean,
				default: true,
			}, // 是否使用在订单列表页面
		},

		data() {
			return {
				faceUrl: '',
			}
		},
		mounted() {
			console.log('我是人脸识别', this.order);
			this.getZfbAuthUrl()
		},

		computed: {
			position: function() {
				return checkPosition.maiduan(this.order, this.isUsedInList)
			}
		},

		methods: {
			//判断按钮是否出现
			judgeGopayOrQianyue() {
				if (this.order.faceAuthStatus == '01' && this.order.status == '13') {
					return true
				} else {
					return false
				}
			},
			/**
			 ** 获取支付宝人脸认证的url
			 */
			getZfbAuthUrl() {
				// this.$onTo(`/pagesMy/maiduan/maiduan?orderId=${getOrderId(this.order)}`)
				console.log('人脸识别要传参的orderId', this.order.orderId);
				this.$request("order/mall/api/order/getFaceAuthCertifyUrl", {
					orderId: this.order.orderId
				}, "post").then(res => {
					this.faceUrl = res.data.faceUrl
				})
			},
			goToZfbAuthent() {
				// window.location.href = this.faceUrl
				let isIosEnv = uni.getSystemInfoSync().platform
				if (isIosEnv == 'ios') {
					let timer1 = null
					timer1 = setTimeout(() => {
						window.open(this.faceUrl, "_blank");
						clearTimeout(timer1);
						timer1 = null
					}, 50); // 延迟0.5秒
				} else {
					window.open(this.faceUrl, "_blank");
				}
			},
		}
	}
</script>

<style>
</style>